<?php

namespace app\agent\model\agent;

use app\agent\model\BaseModel;
use think\Db;

/**
 * 代理商模型
 */
class AgentRes extends BaseModel{
    protected $name = 'agent_res';
    public function add($data){
        $this->allowField(true)->save($data);
        return $this->agent_id;
    }
    /**
     * 获取单个代理信息
     */
    public function getAgentInfo($agentId){
        return Db::name('agent')
            ->where('agent_id', '=', $agentId)
            ->find();
    }
    /**
     * 获取代理商信息
     * @param int|null $agentId
     * @throws \think\exception\DbException
     */
    public static function detail($agentId){
        return Db::name('agent')
            ->where('agent_id', '=', $agentId)
            ->order(['create_time' => 'desc'])
            ->paginate(10, false, [
                'query' => request()->request()
            ]);
        return static::get($agentId ?: []);
    }

    /**
     * 获取代理商列表
     * @param boolean $is_recycle
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($is_recycle = false){
        return Db::name('agent')
            ->where('is_delete', '=', 0)
            ->order(['create_time' => 'desc'])
            ->paginate(10, false, [
                'query' => request()->request()
            ]);
    }



}
